import { Component, OnInit} from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { Router, ActivatedRoute } from "@angular/router"; //路由引入
import { config } from '../../shared/smartadmin.config';

declare var $: any;
declare var echarts: any;
declare var Viewer: any;
@Component({
	selector: 'sa-repaired-detail',
	templateUrl: './repaired-detail.component.html',
	styleUrls: ['./repaired-detail.component.css']
})
export class RepairedDetailComponent implements OnInit {
    tableData = []; //table数据
	parentparentCurPage: number; //父级激活页码
	parentparentRowId: string; //父级Id
	parentRowId: string; //父级Id
	carDeatailUseList = carTypeListObj.carDeatailUseList;
	repairedList: any = [];
	repairedDetailData:any;
	constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {
		activatedRoute.queryParams.subscribe(queryParams => {
			this.parentparentCurPage = queryParams.nowPage || 1;
			this.parentparentRowId = queryParams.parentId || '';
			this.parentRowId = queryParams.id || '';
		});
	}

	ngOnInit() {
		this.load();
	}
	//table刷新
	refresh() {
		this.load();
	}
	//初始化加载list数据
	load() {
		this.jsonApiService.http_obj("sanitation/deviceRepaired/sanitationDeviceRepairedHistory.html", {id:this.parentparentRowId}).subscribe(result => {
		    if(result.data){
		        this.repairedList = result.data;
		        this.repairedDetail(this.parentRowId);
		    }
		})
	}
	repairedDetail(id){
	    this.parentRowId = id;
	    this.jsonApiService.http_obj("sanitation/deviceRepaired/queryDeviceRepairedItemDetails.html", {id:id}).subscribe(result => {
            if(result.data){
                this.repairedDetailData = result.data;
            }
        })
	}
	goBack(){
	    this.router.navigate(['/installation-management/repaired-record'], {queryParams: {id: this.parentparentRowId,nowPage: this.parentparentCurPage}});
	}
	// 跳转维修详细
	goRepaireDetail(row){
		common.setCookie('repaireDetail', JSON.stringify(row));
		this.router.navigate(['/device-management/repaire-detail']);
	}
	// 删除功能
	deleteRow(row){
		this.jsonApiService.confirm_message('此操作将永久删除数据,确认要删除?').then(()=>{
			let reqdata = 'id=' + row.id;
			this.jsonApiService.http("sanitation/deviceRepaired/deleteById.html", reqdata).subscribe(data => {
				this.jsonApiService.message(data.message);
				if(data.success){
					this.load();
				}
			})
		})
	}
	// 图片查看
	activeImg:any = {
	    title:'',
	    url:''
	}
	imgViewer(imageUrl,name,type,modal){
	    this.activeImg.title = name;
	    if(type == 'before'){
	        this.activeImg.title  = '故障图片'+(name+1);
	    }
	    this.activeImg.url = imageUrl;
	    modal.show();
	}
	// 图片关闭
	imgClose(modal){
	    modal.hide();
	}
	//图片放大
	isViewer:Boolean = false;
	viewer:any;
    bigimg(){
        if(this.isViewer && $(".viewer-container").length >0){
            
            if(this.isViewer && $(".viewer-container").length >0){
                this.viewer.destroy();
            }
            
            System.import('assets/js/viewer/viewer.js').then(
                ()=>{System.import('assets/js/viewer/bootstrap.bundle.min.js').then(
                    ()=>{System.import('assets/js/viewer/viewer.css').then(()=>{
                        this.showImg();
                    })
                })
            })
        }else{
            this.showImg();
        }

    }
    showImg(){
        var that = this;
        var imgList = $(".imagesInfo")[0];
        this.viewer = new Viewer(imgList, {
            url: 'src',
            title: function (image) {
                return image.alt + ' (' + (this.index + 1) + '/' + this.length + ')' ; 
            },
        });
        this.isViewer = true;
    }
}